package dao

import (
	"context"
	"mall-portalv2/internal/model"
)

func (d *Dao) QueryUmsMemberWhereID(ctx context.Context, ID int64) (model.UmsMember, error) {
	tb := model.UmsMember{}
	result := model.UmsMember{}

	if err := d.db.WithContext(ctx).Table(tb.TableName()).Where("id = ?", ID).First(&result).Error; err != nil {
		return result, err
	}
	return result, nil
}

func (d *Dao) CreateUmsMember(ctx context.Context, insertModel model.UmsMember) (model.UmsMember, error) {
	tb := model.UmsMember{}
	if err := d.db.WithContext(ctx).Table(tb.TableName()).Create(&insertModel).Error; err != nil {
		return insertModel, err
	}
	return insertModel, nil
}

func (d *Dao) UpdateUmsMember(ctx context.Context, ID int64, upadtes map[string]interface{}) error {
	tb := model.UmsMember{}
	if err := d.db.WithContext(ctx).Table(tb.TableName()).Where("id = ?", ID).Updates(upadtes).Error; err != nil {
		return err
	}
	return nil
}
